<template>
	<z-paging ref="paging" bgColor="#F5F6FA"  class="content" v-model="dataList" @query="queryList">
		<template #top>
			<view class="btns">
				<view class="it" @click="onEdit">
					全部设为已读
				</view>
			</view>
		</template>
		<uni-swipe-action>
			<view class="b" @click="goDetails(item.id)" v-for="(item,index) in dataList">
				<uni-swipe-action-item :right-options="options" @click="onClick($event,item.id)">
					<view class="item">
						
						<view class="h1">
							<view class="h">
								<view class="no-look" v-if="!item.look"></view>{{item.title}}
							</view>
							 <view class="time">{{item.add_time}}</view>
						</view>
						<view class="p">
							{{item.content}}
						</view>
					</view>
				</uni-swipe-action-item>
			</view>
		</uni-swipe-action>
	</z-paging>
</template>

<script setup>
	import {ref} from "vue"
	import {messageSystem,messageSystemDel} from "@/api/user.js"
	import {onShow} from "@dcloudio/uni-app"
	const paging=ref(null)
	const dataList=ref([])
	
	const options=ref([{
				text: '删除',
				style: {
					backgroundColor: '#dd524d'
				}
		}])
	onShow(()=>{
		if(paging.value){
			paging.value.refresh() 
		}
	})
	const onClick=async (e,id)=>{
		let re=await messageSystemDel({params:{id:id,key:"is_del",value:1}})
		paging.value.reload();
	}
	const onEdit=async (e,id)=>{
		let re=await messageSystemDel({params:{id:0,key:"look",value:1,all:1}})
		paging.value.reload();
	}
	const queryList=async (pageNo, pageSize)=>{
		let res=[]
		try {
			let re=await messageSystem({params:{page:pageNo,limit:pageSize}})
			res=re.data.list
		} finally {
			//TODO handle the exception
			paging.value.complete(res);
		}
	}
	const goDetails=(id)=>{
		uni.navigateTo({
			url:'./details?id='+id
		})
	}
</script>

<style lang="scss">
	page{
		background: #F5F6FA;
	}
	.b{
		margin-bottom: 20rpx;
	}
	.btns{
		display: flex;
		justify-content: flex-end;
		padding:10rpx 28rpx;
		font-size: 28rpx;
		line-height: 60rpx;
		color:#999;
		background-color: #fff;
		border-bottom: 20rpx solid #F5F6FA;
	}
	.item{
		padding: 28rpx;
		background-color: #fff;
		position: relative;
		
		.h1{
			font-size: 30rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			.h{
				display: flex;
				align-items: center;
				.no-look {
					width: 10rpx;
					height: 10rpx;
					border-radius: 50%;
					background-color: #1ABB1D;
					margin-right: 10rpx;
				}
			}
			.time{
				font-size: 24rpx;
				color:#aaa;
			}
		}
		.p{
			font-size: 26rpx;
			margin-top:8rpx;
			color:#aaa;
			white-space: nowrap; /* 防止文本换行 */
			  overflow: hidden; /* 隐藏溢出的文本 */
			  text-overflow: ellipsis; /* 显示省略号 */
		}
	}
</style>
